package _Test;/*
* Hello World
*/

import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;

import game.controller.MapInstance;
import game.controller.Region.Region;
import game.util.GameMsg;
import game.packet.GameOps;
import lobby.controller.User;

public class helloWorld extends JPanel implements PropertyChangeListener {

    private JLabel helloWorld;

    private JTextField nameField;

    public helloWorld() {
//        super(new GridBagLayout());
//        GridBagConstraints c = new GridBagConstraints();
//        setUpFormats();

        System.err.println("This is a test err\n");

        
//        //Create text fields
        nameField = new JFormattedTextField("Default");
        nameField.setColumns(15);
        nameField.addPropertyChangeListener("value", this);
//        c.fill = GridBagConstraints.HORIZONTAL;
//        c.gridx = 0;
//        c.gridy = 0;
//        add(nameField,c);
//
//
//        //Create labels
        helloWorld = new JLabel("Hello World!!!");
//        c.fill = GridBagConstraints.HORIZONTAL;
//        c.gridx = 1;
//        c.gridy = 0;
//        c.ipadx = 10;
//        add(helloWorld,c);

        /**
         * Testing area
         */

        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        setBackground(Color.GRAY);

        JLabel france = new JLabel("French Units");
        JLabel gBritian = new JLabel("British Units");
        JLabel Prussia = new JLabel("Prussian Units");
        JLabel Russia = new JLabel("Russian Units");
        JLabel Ottoman = new JLabel("Ottoman Units");
        JLabel Austria = new JLabel("Austrian Units");
        JLabel Spain = new JLabel("Spanish Units");
        JLabel NeutBlack = new JLabel("NeutBlack Units");
        JLabel NeutLGray = new JLabel("NeutLGray Units");
        JLabel NeutDGray = new JLabel("NeutDGray Units");


        france.setForeground(Color.BLUE);
        gBritian.setForeground(Color.RED);
        Prussia.setForeground(Color.PINK);
        Russia.setForeground(Color.ORANGE);
        Ottoman.setForeground(Color.YELLOW);
        Austria.setForeground(Color.GREEN);
        Spain.setForeground(Color.CYAN);
        NeutBlack.setForeground(Color.BLACK);
        NeutLGray.setForeground(Color.LIGHT_GRAY);
        NeutDGray.setForeground(Color.DARK_GRAY);

        add(france);
        add(gBritian);
        add(Prussia);
        add(Russia);
        add(Ottoman);
        add(Austria);
        add(Spain);
        add(NeutBlack);
        add(NeutLGray);
        add(NeutDGray);


//        HeadersComboBox box = new HeadersComboBox(new Object[]{"One", "Two", "Three"});
//        box.setHeaders(new int[]{2});
//        box.setHeaders(new int[]{2,3,4});
        GameMsg.load();
        MapInstance map = new MapInstance();
//        PathFinder pathing = new PathFinder(map);
//
//        NationInstance france = new NationInstance(Nation.FRANCE, 0, LobbyConstants.X, map);
//        NationInstance gb = new NationInstance(Nation.GREAT_BRITAIN, 0, LobbyConstants.X, map);
//        NationInstance prussia = new NationInstance(Nation.PRUSSIA, 0, LobbyConstants.X, map);
//        NationInstance russia = new NationInstance(Nation.RUSSIA, 0, LobbyConstants.X, map);
//        NationInstance ottoman = new NationInstance(Nation.OTTOMANS, 0, LobbyConstants.X, map);
//        NationInstance hungary = new NationInstance(Nation.AUSTRIA_HUNGRY, 0, LobbyConstants.X, map);
//        NationInstance spain = new NationInstance(Nation.SPAIN, 0, LobbyConstants.X, map);
//
////        france.startAlliance(prussia.getNation());
//        france.startAlliance(russia.getNation());
//
//        gb.declareWar(france.getNation());
//        gb.startAlliance(hungary.getNation());
//        gb.startAlliance(ottoman.getNation());
//
//        map.getSeaRegion(GameMsg.getString("AdriaticSea")).addNavalUnits(france.getNavy());
//
//        //nation, useStraits, useSea, isWinter, observeRightsOfPassage, avoidIntercept
//        pathing.findDynamicPaths(gb, true, true, false, true, true);
//
//        LinkedList<Region> pathD = pathing.getDynamicPath(map.getLandRegions()[1], map.getLandRegions()[45]);
//
//        System.out.print("\n\n");
//
//        if (pathD == null)
//            System.out.println("No Path possible");
//        else {
//            System.out.println("Path:");
//            while (pathD.size() > 0 ) {
//                Region r = pathD.pop();
//
//                System.out.print(r.toString());
//                if (pathD.size() > 0)
//                    System.out.print(" ---- ");
//            }
//        }
//        System.out.println();

//        ArrayList<MilitaryUnit> test = new ArrayList<MilitaryUnit>();
//
//        for (MilitaryUnit u : test) {
//            System.out.println("TESTING");
//        }

        //todo TEST GameAddUnitsPacket TEST

//        ArrayList<MilitaryUnit> units = new ArrayList<MilitaryUnit>();
//        units.add(new Infantry(1));
//        units.add(new Infantry(1));
//        units.add(new Infantry(1));
//        units.add(new Infantry(1));
//        units.add(new Infantry(1));
//        units.add(new Infantry(1));
//        units.add(new Infantry(1));
//        units.add(new Cavalry(1));
//        units.add(new Cavalry(1));
//        units.add(new Cavalry(1));
//        units.add(new Artillery(1));
//        units.add(new Artillery(1));
//        units.add(new NavalSquadron(1));
//        units.add(new NavalSquadron(1));
//        units.add(new NavalSquadron(1));
//        units.add(new Admiral(1));
//
//
//        add(new PlacementPanel(units));


    }

    public void propertyChange(PropertyChangeEvent e) {
        Object source = e.getSource();
        System.out.println(nameField.getText());
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame ("HelloWorld!!!");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.add(new helloWorld());

//        frame.setMinimumSize(new Dimension(200,200));
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        System.out.println("Hello World!!!");
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
//                UIManager.put("swing.boldMetal", Boolean.FALSE);
                createAndShowGUI();
            }
        });
    }
}
